package org.hot100_3;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class leetcode763 {
    public List<Integer> partitionLabels(String s) {
        List<Integer> list = new ArrayList<>();

        //key为字符串中的每个字母，value为对应最后出现的下标
        HashMap<Character,Integer> hashMap = new HashMap<>();

        for (int i = 0; i < s.length(); i++) {
            hashMap.put(s.charAt(i),i);
        }

        int start = 0;
        int end = 0;

        for (int i = 0; i < s.length(); i++) {
            end=Math.max(end,hashMap.get(s.charAt(i)));
            if (i==end){
                list.add(end-start+1);
                start=i+1;
            }
        }

        return list;
    }
}
